<template class="body">
  <el-card shadow="never" class="aui-card--fill">
    <el-form ref="form" :model="user" label-width="80px" >
      <el-form-item label="用户名">
        <el-input v-model="user.name"></el-input>
      </el-form-item>
      <el-form-item label="密码">
        <el-input v-model="user.password" show-password>></el-input>
      </el-form-item>
      <el-form-item label="确认密码">
        <el-input v-model="conpass" show-password>></el-input>
      </el-form-item>
      <el-form-item label="邮箱">
        <el-input v-model="user.email"></el-input>
      </el-form-item>
      <el-form-item label="性别">
        <el-radio-group v-model="user.gender">
          <el-radio label="1">男</el-radio>
          <el-radio label="0">女</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="电话">
        <el-input v-model="user.phone"></el-input>
      </el-form-item>
      <el-form-item label="部门">
        <el-radio-group v-model="user.deptId">
          <el-radio label="1">技术部</el-radio>
          <el-radio label="2">长沙分公司</el-radio>
          <el-radio label="3">上海分公司</el-radio>
          <el-radio label="4">市场部</el-radio>
          <el-radio label="5">人人开源集团</el-radio>
          <el-radio label="6">销售部</el-radio>
          <el-radio label="7">产品部</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="真实姓名">
        <el-input v-model="user.realName"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submit">注册</el-button>
        <el-button>取消</el-button>
      </el-form-item>
    </el-form>
  </el-card>
</template>
<script>
export default {
  data() {
    return {
      user: {
        name: '',
        password: '',
        gender: 0,
        phone: '',
        email:'',
        deptId:0,
        realName:""
      },
      conpass: '',
    }
  },
  methods: {
    submit() {
      if (this.user.password != this.conpass) {
        this.open2()
      } else {
        this.$http.post('sys/user', {
          username: this.user.name,
          password: this.user.password,
          gender: this.user.gender,
          email:this.user.email,
          mobile: this.user.phone,
          deptId:this.user.deptId,
          realName:this.user.realName
          // 解构赋值
        }).then(({data: res}) => {
          if (res.msg == "success") {
            this.open1()
            this.user = {};
            this.conpass = ""
          }
        }).catch(() => {
          // console.log(params)
        })
      }
    }, open1() {
      this.$message({
        message: '注册成功',
        type: 'success'
      });
    }, open2() {
      this.$message({
        message: '两次输入的密码不一致',
        type: 'warning'
      });
    }
  }
}
</script>
<style>
.register {
  border-radius: 15px;
  background-clip: padding-box;
  margin: 90px auto;
  width: 350px;
  padding: 35px 35px 15px 35px;
  background: #fff;
  border: 1px solid #eaeaea;
  box-shadow: 0 0 25px #cac6c6;
}
</style>
